Skip to content

Mark generated source as auto-generated and suppress warnings in .g.cs output#51

Merged
dex3r merged 2 commits into
mainfrom
copilot/suppress-warnings-in-generated-code
Mar 4, 2026
Merged

Mark generated source as auto-generated and suppress warnings in .g.cs output#51
dex3r merged 2 commits into
mainfrom
copilot/suppress-warnings-in-generated-code

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 4, 2026

Generated .g.cs files were emitted without an auto-generated marker and could surface compiler warnings from generated code. This updates emitted source to include standard generated-file metadata and warning suppression, plus attribution to the generator and target method.

  • Generated file preamble

    • Added an explicit preamble to all generated method files:
      • // <auto-generated/>
      • generator attribution including target method name
      • #pragma warning disable
    • Implemented in GeneratesMethodPatternSourceBuilder.AppendNamespaceAndTypeHeader(...) so it applies consistently across simple, switch, and fluent generation paths.
  • Generator attribution in output

    • Emitted metadata now includes:
      • generator type: EasySourceGenerators.Generators.GeneratesMethodGenerator
      • generated method name (e.g., GetBoolLabel)
    • This makes origin tracing straightforward in generated artifacts.
  • Tests updated with focused coverage

    • Added a targeted assertion that generated code includes:
      • auto-generated marker
      • generator/method attribution
      • warning suppression pragma
    • Enhanced GeneratedCodeTestHelper with:
      • ReadGeneratedCodeRaw(...) for header-level assertions
      • preamble stripping in ReadGeneratedCode(...) to keep existing exact-content tests stable.
// <auto-generated/>
// Generated by EasySourceGenerators.Generators.GeneratesMethodGenerator for method 'GetBoolLabel'.
#pragma warning disable

namespace EasySourceGenerators.Tests;
Original prompt

This section details on the original issue you should resolve

<issue_title>Generated code should not produce warnings</issue_title>
<issue_description>Generated code files should be clearly marked as automatically generated, hence suppress common warnings.

Maybe also reference this package as the generator?
And maybe even the method that generated this code?</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: dex3r <3155725+dex3r@users.noreply.github.com>
Copilot AI changed the title [WIP] Suppress common warnings in generated code files Mark generated source as auto-generated and suppress warnings in .g.cs output Mar 4, 2026
Copilot finished work on behalf of dex3r March 4, 2026 19:31
@dex3r dex3r self-requested a review March 4, 2026 19:31
@dex3r dex3r marked this pull request as ready for review March 4, 2026 19:36
Copilot AI review requested due to automatic review settings March 4, 2026 19:36
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the GeneratesMethod source generator output to be clearly identified as generated code and to suppress compiler warnings in emitted .g.cs files, improving build signal quality and traceability of generated artifacts.

Changes:

  • Adds a standard generated-file preamble (// <auto-generated/>, generator + target method attribution, and #pragma warning disable) to generated method sources.
  • Extends the test helper to support reading raw generated output vs. preamble-stripped output for stable existing assertions.
  • Adds a targeted test asserting the generated preamble exists in produced output.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
EasySourceGenerators.Tests/GeneratedCodeTestHelper.cs Adds raw read + preamble stripping to keep existing exact generated-code assertions stable.
EasySourceGenerators.Tests/BoolSwitchKeyTests.cs Adds an assertion-focused test validating the new generated-file preamble.
EasySourceGenerators.Generators/GeneratesMethodPatternSourceBuilder.cs Emits auto-generated marker, attribution, and warning suppression at the top of generated sources.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread EasySourceGenerators.Tests/GeneratedCodeTestHelper.cs
@dex3r dex3r merged commit 2137024 into main Mar 4, 2026
6 checks passed
@dex3r dex3r deleted the copilot/suppress-warnings-in-generated-code branch March 4, 2026 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generated code should not produce warnings

3 participants